import axiosServer from '@/api/request'
import type { IResponse } from '../interface'

/* 添加日志  */
export const RequestLogAdd = <T>(mid: number, content: string, category: number = 1): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/log/add',
		method: 'post',
		data: {
			content,
			mid,
			category
		}
	})
}

/* 
  日志列表
*/
export const RequestLogList = <T>(
	name:string = '', //昵称
	pageNo?: number = 1,
	pageSize?: number = 5,
	username?: string = '',
	startTime?: string,
	endTime?: string
): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/log/list',
		method: 'get',
		params: {
			pageNo,
			pageSize,
			username, // 过滤显示当前用户日志
			name, // 昵称
			startTime,
			endTime
		}
	})
}

/**
 * 查询日志
 * @param {} id
 */
export const RequestLogFind = <T>(id: number): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/log/find',
		method: 'get',
		params: {
			id
		}
	})
}

/**
 * 修改日志
 */
export const RequestLogUpdate = <T>(id: number, content: string): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/log/update',
		method: 'post',
		data: {
			id,
			content
		}
	})
}
/**
 * 删除日志
 */
export const RequestLogDelete = <T>(id: number): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/log/delete?id='+id,
		method: 'get',
	})
}

//---------------- 日志回复---------------

/* 添加日志回复  */
export const RequestLogReplyAdd = <T>(message: string, log_id: number, mid: number): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/log/reply/add',
		method: 'post',
		data: {
			message,
			log_id,
			mid
		}
	})
}

/* 
  日志列表
*/
export const RequestLogReplyListPage = <T>(logId: number): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/reply/list',
		method: 'get',
		params: {
			logId
		}
	})
}

/**
 * 删除日志
 */
export const RequestLogReplyDelete = <T>(id: number): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/reply/delete',
		method: 'get',
		params: {
			id
		}
	})
}

/**
 * 公告列表
 */
export const RequestNoticeList = <T>({ nick = '', content = '' }): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/log/notice',
		method: 'get',
		params: {
			nick,
			content
		}
	})
}

/**
 * 添加日志
 */
export const RequestNoticeAdd = <T>(content: string, mid: number): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/log/notice',
		method: 'post',
		data: {
			content,
			mid
		}
	})
}

/**
 * 添加日志
 */
export const RequestNoticeDelete = <T>(id: number): Promise<IResponse<T>> => {
	return axiosServer({
		url: '/api/log/notice',
		method: 'delete',
		params: {
			id
		}
	})
}
export const logApi = {
	RequestLogAdd,
	RequestLogList,
	RequestLogFind,
	RequestLogUpdate,
	RequestLogDelete,
	RequestLogReplyAdd,
	RequestLogReplyListPage,
	RequestLogReplyDelete,
	RequestNoticeList,
	RequestNoticeAdd,
	RequestNoticeDelete
}
